﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Xml;

namespace simpleGUI_QLQTPM
{
    public partial class Form_Help : Form
    {
        //86,134  
        #region Attributes

        public Form _parent = null;
        private List<Image> listImage = new List<Image>();
        private static int indexImage;
        private static bool openState;

        #endregion

        private void InitImage()
        {
            

            //load image
            Image image = simpleGUI_QLQTPM.Properties.Resources.help0;
            listImage.Add(image);
            image = simpleGUI_QLQTPM.Properties.Resources.help1;
            listImage.Add(image);
            image = simpleGUI_QLQTPM.Properties.Resources.help2;
            listImage.Add(image);
            image = simpleGUI_QLQTPM.Properties.Resources.help3;
            listImage.Add(image);
            image = simpleGUI_QLQTPM.Properties.Resources.help4;
            listImage.Add(image);
            image = simpleGUI_QLQTPM.Properties.Resources.help5;
            listImage.Add(image);
            image = simpleGUI_QLQTPM.Properties.Resources.help6;
            listImage.Add(image);
            // khoi tao index cho list image, va picturebox
            indexImage = 0;

            // customize picturebox
            PB_HelpImage1.Image = listImage[indexImage];
            PB_HelpImage1.SizeMode = PictureBoxSizeMode.StretchImage;

            PB_LeftArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.leftarrowhiddeen;
            #region
            // create picturebox
            //PictureBox pb1 = new PictureBox();
            //PictureBox pb2 = new PictureBox();

            //((System.ComponentModel.ISupportInitialize)(pb1)).BeginInit();
            //((System.ComponentModel.ISupportInitialize)(pb2)).BeginInit();
            //this.SuspendLayout();

            //pb1.BackColor = Color.Transparent;
            //pb1.Location = new Point(0, 0);
            //pb1.Size = new System.Drawing.Size(581, 399);
            //Image image1 = simpleGUI_QLQTPM.Properties.Resources.help1;
            //pb1.Image = image1;
            //pb1.SizeMode = PictureBoxSizeMode.StretchImage;
            //listPic.Add(pb1);

            //pb2.BackColor = Color.Transparent;
            //pb2.Location = new Point(581, 0);
            //pb2.Size = new System.Drawing.Size(581, 399);
            //Image image2 = simpleGUI_QLQTPM.Properties.Resources.help2;
            //pb2.Image = image2;
            //pb2.SizeMode = PictureBoxSizeMode.StretchImage;
            //listPic.Add(pb2);

            //PN_HelpImage.Controls.Add(pb1);
            //PN_HelpImage.Controls.Add(pb2);

            //((System.ComponentModel.ISupportInitialize)(pb1)).EndInit();
            //((System.ComponentModel.ISupportInitialize)(pb2)).EndInit();
            //this.ResumeLayout(false);
            #endregion
        }

        public Form_Help()
        {
            InitializeComponent();
            InitImage();
        }

        private void PB_LeftArrow_MouseEnter(object sender, EventArgs e)
        {
            if(indexImage != 0)
                PB_LeftArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.leftarrowclick;
        }

        private void PB_RightArrow_MouseEnter(object sender, EventArgs e)
        {
            if(indexImage < listImage.Count - 1)
                PB_RightArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.rightarrowclick;
        }

        private void PB_LeftArrow_MouseLeave(object sender, EventArgs e)
        {
            PB_LeftArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.leftarrow;
            if (indexImage == 0)
            {
                PB_LeftArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.leftarrowhiddeen;
                PB_RightArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.rightarrow;
            }
        }

        private void PB_RightArrow_MouseLeave(object sender, EventArgs e)
        {
            PB_RightArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.rightarrow;
            if (indexImage == listImage.Count - 1)
            {
                PB_RightArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.rightarrowhidden;
                PB_LeftArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.leftarrow;
            }
        }

        private void PB_LeftArrow_Click(object sender, EventArgs e)
        {
            
            // xac dinh index image can hien thi
            if (indexImage != 0)
            {
                --indexImage;
            }
            PB_HelpImage1.Image = listImage[indexImage];
            //thay doi hien thi arrow
            if (indexImage > 0 && indexImage < listImage.Count - 1)
            {
                PB_LeftArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.leftarrow;
                PB_RightArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.rightarrow;
            }

        }

        private void PB_RightArrow_Click(object sender, EventArgs e)
        {
            
            // xac dinh index image can hien thi
            if (indexImage != listImage.Count() - 1)
            {
                ++indexImage;        
            }
            PB_HelpImage1.Image = listImage[indexImage];
            //thay doi hien thi arrow
            if (indexImage > 0 && indexImage < listImage.Count - 1)
            {
                PB_RightArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.rightarrow;
                PB_LeftArrow.BackgroundImage = simpleGUI_QLQTPM.Properties.Resources.leftarrow;
            }
        }

        /// <summary>
        /// Trang thai cua form khi mo chuong trinh
        /// </summary>
        private void XacDinhTrangThaiBanDau()
        {
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load("config.xml");

                XmlElement root = document.DocumentElement;
                XmlElement element = (XmlElement)root.SelectSingleNode("//OPEN");

                string open = element.InnerText;
                if (open.Equals("true"))
                    CB_chedohienthi.Checked = true;
                else
                    if (open.Equals("false"))
                        CB_chedohienthi.Checked = false;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

        private void Form_Help_Load(object sender, EventArgs e)
        {
            XacDinhTrangThaiBanDau();
        }

        private void CB_chedohienthi_CheckedChanged(object sender, EventArgs e)
        {
            string check = "";
            if (CB_chedohienthi.CheckState == CheckState.Checked)
                check = "true";
            else
                if(CB_chedohienthi.CheckState == CheckState.Unchecked)
                    check = "false";
            XmlDocument document = new XmlDocument();
            document.Load("config.xml");
            XmlElement root = document.DocumentElement;
            XmlElement element = (XmlElement)root.SelectSingleNode("//OPEN");
            element.InnerText = check;
            document.Save("config.xml");
        }
        
    }
}
